//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: baseJs.imgUrl,
    pageIndex:1,
    state:"",
    listData:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.GetSystemNewsAndNotice();
  },

  

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.data.pageIndex++;
    this.GetSystemNewsAndNotice();
  },

  // 
  GetSystemNewsAndNotice: function () {
    var that = this;
    var uid = this.data.uid;
    var pageIndex = this.data.pageIndex;
    var type = this.data.type;
    var listData = this.data.listData;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetSystemNewsAndNotice&Type=0&PageSize=10&PageIndex=" + pageIndex),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        for (var i = 0; i < json.length; i++) {
          json[i].CreateTime = json[i].CreateTime.replace("T", " ");
          json[i].Contents = json[i].Contents.replace(/<[^>]+>/g, "");
          json[i].Contents = json[i].Contents.replace(/&nbsp;/g, "");
          json[i].Links = json[i].Links.split("=")[1];
          listData.push(json[i])
        }
        that.setData({
          listData: listData,
        })
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
      }
    })
  },
})